// Copyright (c) ZeroC, Inc.

using Client;
using IceRpc;
using Microsoft.Extensions.Logging;
using System.Reflection.Metadata;


// Slice module VisitorCenter in Greeter.slice maps to C# namespace VisitorCenter.
using VisitorCenter;

using ILoggerFactory loggerFactory = LoggerFactory.Create(b =>
b
.AddSimpleConsole()
.AddFilter("IceRpc", LogLevel.Debug))
;

var todo = new CallBackTodo();

Router router = new Router().UseLogger(loggerFactory)
    .Map<ICallBackService>(todo);

var clientOption = new ClientConnectionOptions
{
    ServerAddress = new ServerAddress(new Uri("icerpc://localhost:10010")),
    Dispatcher = router
};
await using var connection = new ClientConnection(clientOption,logger:loggerFactory.CreateLogger<ClientConnection>());

Pipeline pipeline=new Pipeline()
    .UseLogger(loggerFactory)
    .Into(connection);

// GreeterProxy is a struct generated by the Slice compiler.
var greeter = new GreeterProxy(pipeline);

await connection.ConnectAsync();

string greeting = await greeter.GreetAsync(Environment.UserName);

Console.WriteLine(greeting);

await CancelKeyPressed;
await connection.ShutdownAsync();
